package com.whq.thrift.api.web.admin.db.test;

import java.util.Map;

import org.apache.ibatis.jdbc.SqlBuilder;

import com.whq.common.StringUtil;

public class IceTestSqlProvider {
	
	public String getIceTestCaseByMapSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("*");
		SqlBuilder.FROM("t_ice_test_case");

		if ((parameter.get("name") != null) && (StringUtil.isNotBlank(parameter.get("name").toString()))) {
			SqlBuilder.WHERE("name like #{name}");
		}

		if(parameter.get("method")!=null && (StringUtil.isNotBlank(parameter.get("method").toString()))){
			SqlBuilder.WHERE("method like #{method}");
		}
		
		if(parameter.get("manager")!=null && (StringUtil.isNotBlank(parameter.get("manager").toString()))){
			SqlBuilder.WHERE("manager like #{manager}");
		}
		
		SqlBuilder.ORDER_BY("id asc");
		return SqlBuilder.SQL() + " limit #{beginIndex}, #{maxCount} ";
	}
	
	public String getSelectCountSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("count(*)");
		SqlBuilder.FROM("t_ice_test_case");

		if ((parameter.get("name") != null) && (StringUtil.isNotBlank(parameter.get("name").toString()))) {
			SqlBuilder.WHERE("name like #{name}");
		}

		if (parameter.get("method") != null && (StringUtil.isNotBlank(parameter.get("method").toString()))) {
			SqlBuilder.WHERE("method like #{method}");
		}
		
		if(parameter.get("manager")!=null && (StringUtil.isNotBlank(parameter.get("manager").toString()))){
			SqlBuilder.WHERE("manager like #{manager}");
		}
		return SqlBuilder.SQL();
	}
}
